import { CoolController, BaseController } from '@cool-midway/core';
import { Body, Inject, Post } from '@midwayjs/core';
import { SubmitDemandRequestDTO, UserDemandDetailDTO } from '../../dto/request';
import { DemandRequestService } from '../../service/request';
import type { DemandRequestPagePayload } from '../../service/request';
import { DemandTeamRequestEntity } from '../../entity/request';

@CoolController({
  api: [],
  entity: DemandTeamRequestEntity,
})
export class AppDemandRequestController extends BaseController {
  @Inject()
  ctx;

  @Inject()
  demandRequestService: DemandRequestService;

  /**
   * 用户提交服务需求
   */
  @Post('/submit', { summary: '提交需求给服务团队' })
  async submit(@Body() dto: SubmitDemandRequestDTO) {
    await this.demandRequestService.submit(this.ctx.user.id, dto);
    return this.ok();
  }

  /**
   * 用户查看自己的需求分页
   */
  @Post('/myPage', { summary: '查询我提交的需求列表' })
  async myPage(@Body() query: DemandRequestPagePayload) {
    return this.ok(
      await this.demandRequestService.pageByUser(this.ctx.user.id, query ?? {})
    );
  }

  /**
   * 用户查看需求详情
   */
  @Post('/myDetail', { summary: '查询我提交的需求详情' })
  async myDetail(@Body() dto: UserDemandDetailDTO) {
    return this.ok(
      await this.demandRequestService.detailByUser(this.ctx.user.id, dto.requestId)
    );
  }
}


